<?php $this->load->view('inc/header'); ?>
<style>
  table {
    background:#EFEFEF;
	-moz-border-radius-topleft: 3px;
	-moz-border-radius-topright: 3px;
	-moz-border-radius-bottomright: 3px;
	-moz-border-radius-bottomleft: 3px;
	border-top-left-radius: 3px;
	border-top-right-radius: 3px;
	border-bottom-right-radius: 3px;
	border-bottom-left-radius: 3px; 	
  }
  .oddCSS{
  	background:#5FAFAF;
  	-moz-border-radius-topleft: 3px;
	-moz-border-radius-topright: 3px;
	-moz-border-radius-bottomright: 3px;
	-moz-border-radius-bottomleft: 3px;
	border-top-left-radius: 3px;
	border-top-right-radius: 3px;
	border-bottom-right-radius: 3px;
	border-bottom-left-radius: 3px; 
  }
</style>
<?php
	$this->db->join('blog_category','blog_category.b_category_id=blog.b_category_id');
	$this->db->join('membership','membership.member_id=blog.blog_author');
	$this->db->where('blog_id',$id);
	$query = $this->db->get('blog');
	
	foreach($query->result() as $rows){
		/*blog tables*/
				$blog_id = $rows->blog_id;
				$blog_entry_name = $rows->blog_entry_name;
				$blog_content = $rows->blog_content;
				$blog_create_date = $rows->blog_create_date;
				
				$b_category_id = $rows->b_category_id;
				$category_name = $rows->category_name;
				
		/*memberahip tables*/
				$member_id = $rows->member_id;
				$firstname = $rows->firstname;
				$lastname = $rows->lastname;
				$nickname = $rows->nickname;
				$member_display = $rows->member_display;
	}
?>

<!--one colunm-->
<div class="grid_12" style="background-color:#CCCCCC; padding-top:20px;">
<div class="grid_12 alpha" id="one_cols1">
	<div id="topic" style="position:relative;">
    	<?php
			$this->db->where('blog_id',$blog_id);
		 	$query_hits = $this->db->get('blog_views_log');
			$num_rows = $query_hits->num_rows();
		?>
		<div id="topic_text" style="position:absolute;"><?=$blog_entry_name?></div>
        <div id="view_counts" style="position:absolute; right:40px;"><?=$num_rows?>&nbsp;Visitor hits</div>
    </div>
</div>
<div class="grid_12 alpha"  id="one_cols2">
<div style="padding-left:15px;">
	<div id="entry_description" style="-moz-border-radius-topleft: 5px;
-moz-border-radius-topright: 5px;
-moz-border-radius-bottomright: 5px;
-moz-border-radius-bottomleft: 5px;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px; background:#E7F4F8; padding:4px; width:865px;">
	<div id="member_avatar" style="position:relative;">
                    <?php
                    	if($member_display == NULL)
                        {
                     ?>
                            <div id="avatar"><img src="<?=base_url()?>km_resource/member_display/null.png" width="60" height="60"/></div>
                    <?php
                        }
                        else
                        {
                     ?>
                            <div id="avatar"><img src="<?=base_url()?>km_resource/member_display/<?=$member_display?>" width="60" height="60"/></div>
                    <?php
                        }
                    ?>
                    
                    <?php
					//query record of comment
					$count_comment1 = $this->db->query('select * from blog_comment where blog_id = "'.$blog_id.'"');
					$count_comment = $count_comment1->num_rows();
					?>
                    <div id="e_1" style="position:absolute; left:70px; top:0px; font-size:12px;">Created Date: <?php $d = mysql_to_unix($blog_create_date); echo unix_to_human($d); ?>&nbsp;&nbsp;|&nbsp;By&nbsp;<?=$firstname?>&nbsp;<?=$lastname?>&nbsp;(<?=$nickname?>)</div>
                    <div id="e_2" style="position:absolute; left:70px; top:15px; font-size:12px;"><a href="#">Comment&nbsp;(<?=$count_comment?>)</a>&nbsp;|&nbsp;Like&nbsp;(&nbsp;)&nbsp;DisLike&nbsp;(&nbsp;)</div>
                    <div id="e_3" style="position:absolute; left:70px; top:35px; font-size:12px;">Category: <a href="<?=base_url()?>blog/category/<?=$b_category_id?>"><?=$category_name?></a></div>
                    
                    <!-- point vote -->
<script type="text/javascript">
	//vote up
	$(function(){
	$("#vote_up").click(function(){
		var url="<?=base_url()?>blog/vote_up";
		var dataSet={member_id: <?=$this->session->userdata('member_id')?>, blog_id: <?=$blog_id?> };
		//$('#choose_staff2').empty().html('<p><center><img src="<?=base_url()?>images/ajax-loader.gif"/></center></p>');
		$.post(url,dataSet,function(data){
    		//alert("Success "+dataSet.staff_id+dataSet.org_id);
			
			if(data){
				alert("คุณได้ทำการโหวต เรียบร้อย!");
				$("#like_vote_area").html(data);
			}
			else{
				alert("ขออภัย! คุณไม่สามารถโหวตซ้ำได้\nเนื่องจากคุณได้ทำการลงคะแนนให้กับบล็อกนี้แล้ว");
			}
 		 });
	});
	
	//vote down
	$("#vote_down").click(function(){
		var url="<?=base_url()?>blog/vote_down";
		var dataSet={member_id: <?=$this->session->userdata('member_id')?>, blog_id: <?=$blog_id?> };
		$.post(url,dataSet,function(data){
    		//alert("Success "+dataSet.staff_id+dataSet.org_id);
			
			if(data){
				alert("คุณได้ทำการโหวต เรียบร้อย!");
				$("#dislike_vote_area").html(data);
			}
			else{
				alert("ขออภัย! คุณไม่สามารถโหวตซ้ำได้\nเนื่องจากคุณได้ทำการลงคะแนนให้กับบล็อกนี้แล้ว");
			}
 		 });
	});
});
</script>
<!-- close point vote -->
                    
                    <!-- like vote-->
                    <div id="vote" style="position:absolute; right:85px; top:0px; background:#008080; width:70px; height:60px; color:#FFFFFF; -moz-border-radius-topleft: 6px;
-moz-border-radius-topright: 6px;
-moz-border-radius-bottomright: 6px;
-moz-border-radius-bottomleft: 6px;
border-top-left-radius: 6px;
border-top-right-radius: 6px;
border-bottom-right-radius: 6px;
border-bottom-left-radius: 6px;" align="center">
<!-- display point vote-->
<?php
	$this->db->select_sum('like_vote');
	$this->db->where('blog_id',$id);
	$query_like_vote = $this->db->get('blog_vote');
	foreach($query_like_vote->result() as $i){
		$like_vv = $i->like_vote;
	}
?>
<div id="like_vote_area" style="font-size:large; padding-top:5px">
	<?=$like_vv?>
</div>
<!-- close display point vote-->


<div id="ico_vote" style="padding-top:5px; cursor:pointer;"><span id="vote_up"><img src="<?=base_url()?>images/graphic/thumb-up.png"/></span></div>

</div> 
<!-- close like vote-->

<!-- dislike vote-->
<div id="vote" style="position:absolute; right:4px; top:0px; background:#F34D09; width:70px; height:60px; color:#FFFFFF; -moz-border-radius-topleft: 6px;
-moz-border-radius-topright: 6px;
-moz-border-radius-bottomright: 6px;
-moz-border-radius-bottomleft: 6px;
border-top-left-radius: 6px;
border-top-right-radius: 6px;
border-bottom-right-radius: 6px;
border-bottom-left-radius: 6px;" align="center">
<!-- display point vote-->
<?php
	$this->db->select_sum('dislike_vote');
	$this->db->where('blog_id',$id);
	$query_dislike_vote = $this->db->get('blog_vote');
	foreach($query_dislike_vote->result() as $o){
		$dislike_vv = $o->dislike_vote;
	}
?>
<div id="dislike_vote_area" style="font-size:large; padding-top:5px">
	<?=$dislike_vv?>
</div>
<!-- close display point vote-->
<div id="ico_vote" style="padding-top:5px; cursor:pointer;"><span id="vote_down"><img src="<?=base_url()?>images/graphic/thumb.png"/></span></div>
</div>
<!-- close dislike vote-->
</div> 
            
</div>

<br/>
	<div id="blog_content" style="font-size:small; width:870px;"><?=htmlspecialchars_decode($blog_content)?></div>
</div>
</div>
<div class="grid_12 alpha" id="one_cols3"></div>
</div>
<div class="clear"></div>
<!--end one column-->

<!--list comment-->
<div class="grid_12" style="background-color:#CCCCCC; padding-bottom:10px;" >
    <div id="top_blog_post">
    	<div id="text_topic" style="position:relative; top:60px; left:20px; font-weight:bold; color:#999999;">
        	<div><img src="<?=base_url()?>images/graphic/1296748696_comment_reply.png" style="vertical-align:sub;">&nbsp;<?=$blog_entry_name?></div></div>
    </div>
    
    <div id="middle_blog_post">
    <script>
	function confirm_delete_comment(id, blog_id, nickname){
									var con = confirm('Delete your comment ID: '+id);
									if(con==true){
										window.location.href = "<?=base_url()?>blog/delete_comment/"+id+"/blog_id/"+blog_id+"/"+nickname;
									}
								}
	</script>
    <div id="show_comment_list" style="padding-left:80px; padding-top:15px;">
    	<?php
		//begin query
			$this->db->limit(5);
			$this->db->order_by('comment_id','desc');
			$this->db->join('membership','membership.member_id=blog_comment.member_id');
			$this->db->where('blog_id',$blog_id);
			$query_blog_comment = $this->db->get('blog_comment');
			foreach($query_blog_comment->result() as $blog_comment){
		?>
        <div style="padding-left: 6px; width: 700px; margin-bottom: 20px; margin-left: 6px; border-bottom: thin dashed #FFFFFF; background:#B4BFB3; -moz-border-radius-topleft: 4px;
-moz-border-radius-topright: 4px;
-moz-border-radius-bottomright: 4px;
-moz-border-radius-bottomleft: 4px;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
border-bottom-left-radius: 4px; ">
      		<div style="float: left; width: 42px; padding:2px;">
           		<?php
							if($blog_comment->member_display == NULL){
						?>
                        	<img src="<?=base_url()?>km_resource/member_display/null.png" width="40" height="40"/>
                        <?php	
							}
							else{
						?>
                        	<img src="<?=base_url()?>km_resource/member_display/<?=$blog_comment->member_display?>" width="40" height="40"/>
                        <?php	
							}
						?>
            </div>
            <div style="width: 640px; font-size:11px;">
                <div id="author_post" style="width:680px; position:relative;">
                	By&nbsp;<?=$blog_comment->firstname?>&nbsp;<?=$blog_comment->lastname?>&nbsp;(<?=$blog_comment->nickname?>)&nbsp;|&nbsp;Date&nbsp;<?=$blog_comment->date_posted?>&nbsp;|&nbsp;#<?=$blog_comment->comment_id?>
                    	<div id="delete_msg" style="position:absolute; right:0px; top:0px;">
							<?php
                                        if($this->session->userdata('member_id')==$blog_comment->member_id){
                                    ?>
                                        <a href="javascript:confirm_delete_comment(<?=$blog_comment->comment_id?>, <?=$id?>, '<?=$nickname?>')">delete ?</a>
                                    <?php
                                        }
                                    ?>   
               		 	</div>
                </div>
                <div id="c_comment"  style="width:650px;">
                	<?=htmlspecialchars_decode($blog_comment->comment_details)?>
                </div>
                
            </div>
            <div style="clear: both;"></div>
        </div>
        
        <?php
        }	//emd foreach
		?>
    </div>
    
    <!-- post area -->
    <div id="post_area">
    	
    	<div id="editor" style="float:left; padding-left:80px; padding-top:15px;">
        	<!--comment areas-->
			<?php
                $is_logged_in = $this->session->userdata('is_logged_in');
                if(!isset($is_logged_in) || $is_logged_in == true){
            ?>
                    <form action="<?=base_url()?>blog/add_comment" method="post"> 
                        <textarea name="content_3" id="content_3">
                        </textarea>
                        <?php echo display_ckeditor($ckeditor_3); ?>
                        </textarea>
                        <input type="hidden" value="<?=$member_id?>" name="member_id">
                        <input type="hidden" value="<?=$blog_id?>" name="blog_id">
                    </form>    
				
		<!--close comment areas-->
        </div>
        <div id="avatar_post" style="width:250px; float:right; padding-top:15px;">
        	<?php
						$this->db->where('member_id',$this->session->userdata('member_id'));
						$q_post = $this->db->get('membership');
						foreach($q_post->result() as $qqq){
							$mm = $qqq->member_display;
							$nn = $qqq->nickname;
						}
                    	if($mm)
                        {
                     ?>
                           <div id="avatar"><img src="<?=base_url()?>km_resource/member_display/<?=$mm?>" width="90" height="90"  style="border:thick solid #C3CFC2; padding:2px;"/></div>
                           <div id="nickname" style="font-size:11px;">Post by: <?=$nn?></div>
                    <?php
                        }
                    ?>
                    

 
		<!--notice-->
			<?php
            }
            else
            {
            ?>
                <div style="font-size:small;">
                    <span style="padding-left:25px;">"Please Register or Login for comment."</span>
                </div>    
			<?php
            }
            ?>
        <!--close notice-->
           </div>    
        
        <div style="clear:both;"></div>
        </div>
        <!-- close post area -->
        
    </div>
    <div id="bottom_blog_post">
    	&nbsp;
    </div>
</div>
<!-- close list comment -->


<div class="clear"></div>
<?php $this->load->view('inc/footer'); ?>